using System.Collections.Generic;
using Dream.ScenesLoader.SceneData;
using Light;
using Light.Assets.Scripts.EventManager;
using UnityEngine;

namespace Dream.ScenesLoader
{
    public class SceneController : MonoBehaviour
    {
        public bool isSend;
        public bool isExit;

        [SerializeField] private List<GameSceneSO> sceneDataList = new();

        private void Awake()
        {
            EventManager.Register<NextSceneLoad>(EnterDream);
        }

        private void OnDestroy()
        {
            EventManager.Unregister<NextSceneLoad>(EnterDream);
        }

        // 进入梦境
        private void EnterDream(NextSceneLoad @event)
        {
            using var evt = SceneLoadEvent.Get();
            evt.isExitScene = @event.isExitScene;
            evt.isFadeScreen = @event.isFadeScreen;
            if (!@event.isExitScene)
                evt.sceneData = sceneDataList[@event.sceneDataIndex];
            EventManager.SendEvent(evt);
        }
    }
}